/**=========================================================
 * Service: datepicker.js
 =========================================================*/

App.service('Datepicker', ['Utils',
    function(utils) {
        'use strict';
        
        return {
            init: function($scope, options) {
                var defaultOptions = {
                    optionModel: 'date', 
                    initValue: utils.addDate(new Date(), "day", -1)
                }
                
                var finalOptions = utils.isEmpty(options) ? defaultOptions : angular.extend(defaultOptions,options);
                
                if (utils.isEmpty($scope.datepickers)) {
                    $scope.datepickers = {}
                }
                 
                $scope.datepickers[finalOptions.optionModel] = {
                    date: finalOptions.initValue,
                    dateOptions: {
                        startingDay: 1 
                    },
                    opened: false
                };
                return {
                    scope: $scope,
                    options: finalOptions,
                    getDate: function(){
                        return $scope.datepickers[this.options.optionModel].date;
                    },
                    setDate: function(newVal){
                        $scope.datepickers[this.options.optionModel].date = newVal;
                    }
                }
            }
        }
    }
]);
